<template>
    <div class="wel-top-page">
        <div class="time">
            <span>{{ time1 }}</span>
            <div>
                <span>{{ time2 }}</span>
                <span>{{ time3 }}</span>
            </div>
        </div>
        <i class="title">臣工云控智能管理系统</i>
        <div class="click">
            <div class="top-user">
                <el-dropdown>
                    <img class="yonghu" src="../../images/yonghu-10@2x.png">
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item @click="logout" divided>退出登录</el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </div>
            <img src="../../images/houtai@2x.png" alt="" @click="goDevice">
        </div>
    </div>
</template>

<script>

export default {
    data () {
        return {
            timer: null,
            time1: '',
            time2: '',
            time3: ''
        };
    },
    created () {
        this.timer = setInterval(() => {
            this.getTime()
        }, 1000);
    },
    methods: {
        goDevice () {
            this.$router.push({ path: "/desk/iotdevice" });
        },
        getTime () {

            // 获取当前时间
            const now = new Date();

            // 格式化时分（HH:MM）
            this.time1 = `${now.getHours().toString().padStart(2, '0')}:${now.getMinutes().toString().padStart(2, '0')}`;

            // 星期几映射表
            const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
            this.time2 = weekdays[now.getDay()];

            // 格式化年月日（YYYY/MM/DD）
            this.time3 = `${now.getFullYear()}/${(now.getMonth() + 1).toString().padStart(2, '0')}/${now.getDate().toString().padStart(2, '0')}`;
        },
        logout () {
            this.$confirm(this.$t("logoutTip"), this.$t("tip"), {
                confirmButtonText: this.$t("submitText"),
                cancelButtonText: this.$t("cancelText"),
                type: "warning"
            }).then(() => {
                this.$store.dispatch("LogOut").then(() => {
                    this.$router.push({ path: "/login" });
                });
            });
        }
    },
    beforeUnmount () {
        clearInterval(this.timer)
    }
}
</script>

<style lang="scss">
.wel-top-page {
    width: 100%;
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;

    .time {
        display: flex;
        align-items: center;
        margin-left: 20px;
        width: 300px;

        >span {
            font-size: 35px;
        }

        >div {
            display: flex;
            flex-direction: column;

            span {
                font-size: 14px;
            }
        }
    }

    .title {
        font-size: 42px;
        margin-top: 10px;
        flex: 1;
        text-align: center;
        display: block !important;
    }

    .click {
        width: 300px;
        margin-right: 20px;
        display: flex;
        flex-flow: row-reverse;

        img {
            width: 20px;
            cursor: pointer;

            &.yonghu {
                margin-right: 20px;
            }
        }
    }
}
</style>
